package com.flatlyapps.shoppinglist;

import android.text.Editable;
import android.text.TextWatcher;

public class DecimalPlaceListener implements TextWatcher{

	private int decimalPlace;

	public DecimalPlaceListener(int decimalPlace){
		this.decimalPlace = decimalPlace;
	}

	@Override
	public void afterTextChanged(Editable arg0) {
		String text = arg0.toString();
		if(text.contains(".")){
			int pointIndex = text.indexOf(".");
			if(text.length()-(pointIndex +1) > decimalPlace){
				arg0.delete(text.length()-1, text.length());
			}
		}
	}

	@Override
	public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
			int arg3) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		
	}

}
